<?php
	include_once("config.php");
	// step 1: get all of the info from the request
	// TO-DO: establish user session information
	//$user = "temp";
	session_start();
	$user = $HTTP_SESSION_VARS['username']; 
	
	$content = $_POST['content'];
	$playlist = $_POST['playlist']; 
	
	// step 2: check to see if the playlist does exist in the database
	db_connect();
	$sql = "select * from ajax_video where username='$user' and playlist='$playlist'"; 
	$result = mysql_query($sql) or die("An error has occured: ".mysql_error()." sql: ".$sql);
		
	if (mysql_num_rows($result) > 0) {
		// run update:
		$sql = "update ajax_video
				set json = '$content'
				where username='$user' and
					  playlist='$playlist'"; 
	} else {
		// new entry, run insert:
		$sql = "insert into ajax_video VALUES ('', '$user', '$playlist', '$content')";
	}
	
	mysql_query($sql) or die("An error has occured: ".mysql_error()." sql: ".$sql);
	
?>